package com.IR.user.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.IR.shop.po.Cars;

import com.IR.user.service.BCarsBiz;

import net.sf.json.JSONArray;

@Controller
public class BCarsAction {
	@Resource
	public BCarsBiz biz;
	private Cars cars;
	private List<Cars> list;
	public Cars getCars() {
		return cars;
	}
	public void setCars(Cars cars) {
		this.cars = cars;
	}
	public List<Cars> getList() {
		return list;
	}
	public void setList(List<Cars> list) {
		this.list = list;
	}
	
	@RequestMapping(value="/showUserCar.do")
	public void showUserCar(HttpServletRequest request,HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long userid=new Long(request.getParameter("userid"));
		list=biz.showUserCar(userid);
		try {
			PrintWriter out = response.getWriter();
			String str=JSONArray.fromObject(list).toString();
			out.println(str);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@RequestMapping(value="/showCar.do")
	public void showCar(HttpServletRequest request,HttpServletResponse response) throws IOException {
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Long userid=new Long(request.getParameter("userid"));
		Long proid=new Long(request.getParameter("proid"));
		list=biz.showCar(userid, proid);
		PrintWriter out = response.getWriter();
		if(list.size()==0) {
			out.println(1);
		}else {
			out.println(0);
		}
	}
}
